export const getOptions = (oldData) => {
  let data = oldData.filter((item) => item.data > 0)
  if (oldData.length !== 0 && data.length === 0) {
    data = [1]
  }
  const gap = 2
  // const jianbian = '33'
  const jianbian = ''
  return {
    tooltip: {
      show: true,
      formatter: (e) => {
        if (data?.[e.dataIndex]?.label) {
          return e.marker + ' ' + data?.[e.dataIndex]?.label + ' ' + e.value
        } else {
          return ''
        }
      },
    },
    series: [
      {
        type: 'pie',
        radius: ['130%', '160%'],
        center: ['50%', '100%'],
        startAngle: 180,
        label: {
          show: true,
          formatter (param) {
            return Math.ceil(param.percent * 2) + '%'
          },
        },
        data: [
          ...data.map((item) => ({
            value: item.data,
            itemStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: item.color + jianbian,
                  },
                  {
                    offset: 1,
                    color: item.color,
                  },
                ],
                global: false, // 缺省为 false
              },
            },
            label: {
              fontSize: 30,
              color: item.color,
              show: true,
            },
            labelLine: {
              length: 3,
              length2: 3,
            },
          })),
          {
            value: data.map((item) => item.data).reduce((a, b) => a + b),
            itemStyle: {
              color: 'none',
              decal: {
                symbol: 'none',
              },
            },
            label: {
              show: false,
            },
          },
        ],
      },
      {
        type: 'pie',
        radius: ['110%', '120%'],
        center: ['50%', '100%'],
        startAngle: 180,
        label: {
          show: true,
          formatter (param) {
            return param.percent * 2 + '%'
          },
        },
        data: [
          ...data
            .map((item, i) => [
              {
                value: i === data.length - 1 ? item.data : item.data - gap,
                itemStyle: {
                  color: '#16517E',
                },
                label: {
                  show: false,
                },
              },
              {
                value: gap,
                itemStyle: {
                  color: i === data.length - 1 ? '#16517E' : 'transparent',
                },
                label: {
                  show: false,
                },
              },
            ])
            .flat(),
          {
            value: data.map((item) => item.data).reduce((a, b) => a + b),
            itemStyle: {
              color: 'none',
              decal: {
                symbol: 'none',
              },
            },
            label: {
              show: false,
            },
          },
        ],
      },
      {
        type: 'pie',
        radius: ['103%', '106%'],
        center: ['50%', '100%'],
        startAngle: 180,
        label: {
          show: true,
          formatter (param) {
            return param.percent * 2 + '%'
          },
        },
        data: [
          ...data
            .map((item, i) => [
              {
                value: i === data.length - 1 ? item.data : item.data - gap,
                itemStyle: {
                  color: '#16517E',
                },
                label: {
                  show: false,
                },
              },
              {
                value: gap,
                itemStyle: {
                  color: i === data.length - 1 ? '#16517E' : 'transparent',
                },
                label: {
                  show: false,
                },
              },
            ])
            .flat(),
          {
            value: data.map((item) => item.data).reduce((a, b) => a + b),
            itemStyle: {
              color: 'none',
              decal: {
                symbol: 'none',
              },
            },
            label: {
              show: false,
            },
          },
        ],
      },
    ],
  }
}
